package group32.client;

import com.google.gwt.core.client.JavaScriptObject;

public class FriendBrowse {
	public static int level;
	
	public static final native void addToGraph(final JavaScriptObject ht, final String json,int curUser,int person) /*-{
	var content = JSON.parse(json);
	var plot=true;
	ht.graph.eachBFS(curUser,function(node){
		var newNode=ht.graph.getNode(person);
		if(newNode._depth>=3)
			plot=false;
	});
	if(plot)
		ht.op.sum(content, { type: "fade:con", fps: 4, duration: 1000, hideLabels: false }); 
	else
		ht.refresh();
}-*/;


/**
 * Creates a JavaScript Infovis Toolkit hypertree
 * 
 * @param json
 * @return
 */
public static final native JavaScriptObject createGraph(final String json, final FriendBrowser parent,int curUser) /*-{
var content=JSON.parse(json);
 
		 //init Hypertree
		var ht = new $wnd.$jit.Hypertree({
		    //id of the visualization container
		    injectInto: 'infovis',
		    //By setting overridable=true,
		    //Node and Edge global properties can be
		    //overriden for each node/edge.
		    Node: {
		        overridable: true,
		        'transform': false,
		        color: "#f00"
		        
		    },
		
		    Edge: {
		        //overridable: true,
		        color: "#000"
		    },
		    //calculate nodes offset
		    offset: 0.15,
		    //Change the animation transition type
		    transition: $wnd.$jit.Trans.Back.easeOut,
		    //animation duration (in milliseconds)
		    duration:1000,
			
			onBeforePlotNode:function(node){
		        if(node.data.usertype=="S")
		        node.Node.color="#01256E";
		        else
		        node.Node.color="#95001A";
			},
			
		    //Attach event handlers on label creation.
		    onCreateLabel: function(domElement, node){
		        domElement.innerHTML = node.name;
		        domElement.style.cursor = "pointer";
		        domElement.onclick = function () {
					parent.@group32.client.FriendBrowser::drawNodeAndNeighbors(ILjava/lang/String;)(node.id,node.data.usertype);
					parent.@group32.client.FriendBrowser::getProfile(ILjava/lang/String;Ljava/lang/String;)(node.id,node.data.usertype,node.data.username);
					console.debug("Clicked");
		            ht.onClick(node.id, { hideLabels: false });
		         };
		    },
		    //This method is called when moving/placing a label.
		    //You can add some positioning offsets to the labels here.
		    onPlaceLabel: function(domElement, node){
		        var width = domElement.offsetWidth;
		        var intX = parseInt(domElement.style.left);
		        intX -= width / 2;
		        domElement.style.left = intX + 'px';
		    },
		    onAfterCompute: function(){
		    }
		});

		//load JSON graph.
		ht.loadJSON(content, 2);
		//compute positions and plot
		ht.refresh();
		//end
		ht.controller.onBeforeCompute(ht.graph.getNode(ht.root));
		ht.controller.onAfterCompute();
		return ht;


}-*/;


}